<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //父类，动物
        function Animal(name,color){
            this.name=name;
            this.color=color;
        }
        //在父类的原型上定义run函数，所有实例共享
        Animal.prototype.run=function(){
            console.log("动物在跑");
        }

        //子类，狗
        function Dog(name,color,weight){  //重量
            //1、借调父类构造器初始化属性值，继承属性
            Animal.call(this,name,color);
            this.weight=weight;
        }
        //将父类的原型给子类
        //Dog.prototype=Animal.prototype;
        //2、实例化父类对象作为子类的原型
        Dog.prototype=new Animal();  //__proto__==Animal.prototype
        Dog.prototype.catch=function(){
            console.log("狗在抓耗子");
        }

        var dog=new Dog("小狗","白色","3kg");
        dog.run();
        dog.catch();
        console.log(dog);
        console.log(new Animal());

        //3、将原型的构造器指回子类
        Dog.prototype.constructor=Dog;
        console.log(Dog.prototype.constructor);
    </script>
</body>
</html>